home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Trusted Irix /B 4.0.4
/
Trusted-Irix B-4.0.1.iso
/
dist
/
eoe1.idb
/
bin
/
basename.z
/
basename
Wrap
Text File
|
1992-04-03
|
963b
|
26 lines
#! /bin/sh
# Copyright (c) 1984 AT&T
# All Rights Reserved
# THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
# The copyright notice above does not evidence any
# actual or intended publication of such source code.
#ident "@(#)basename:basename.sh 1.7"
#ident "$Header: /src_trees/calypso/att/usr/src/cmd/basename/RCS/basename.sh,v 1.4 86/12/08 18:00:34 bruce Exp $"
if [ $# -gt 2 ]
then
echo >&2 "Usage: basename [ path [ suffix-pattern ] ]"
exit 1
fi
# If no first argument or first argument is null, make first argument
# "." Add beginning slash, then remove trailing slashes, then remove
# everything up through last slash, then remove suffix pattern if
# second argument is present.
# If nothing is left, first argument must be of form //*, in which
# case the basename is /.
exec /bin/expr \
"/${1:-.}" : '\(.*[^/]\)/*$' : '.*/\(..*\)' : "\\(.*\\)$2\$" \| \
"/${1:-.}" : '\(.*[^/]\)/*$' : '.*/\(..*\)' \| \
"/${1:-.}" : '.*/\(..*\)'